import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';

/// 当子widget拦截了事件时，外层无法获取Gesture时，该类可以帮助你获取外层的Gesture点击事件，以便解决child事件冲突的影响
class KqTapGestureListener extends StatelessWidget {
  final Widget? child;
  final GestureTapCallback? onTap;

  const KqTapGestureListener({super.key, required this.child, this.onTap});

  @override
  Widget build(BuildContext context) {
    return RawGestureDetector(gestures: {
      _MultipleTapGestureRecogniser:
          GestureRecognizerFactoryWithHandlers<_MultipleTapGestureRecogniser>(
              () => _MultipleTapGestureRecogniser(),
              (_MultipleTapGestureRecogniser instance) {
        instance.onTap = () {
          onTap?.call();
        };
      })
    }, child: child);
  }
}

class _MultipleTapGestureRecogniser extends TapGestureRecognizer {
  @override
  void rejectGesture(int pointer) {
    acceptGesture(pointer);
  }
}
